<!-- 搜索表单 -->
<template>
    <el-card shadow="never" >
      <el-form
        label-width="77px"
        class="ele-form-search"
        @keyup.enter.native="search"
        @submit.native.prevent
      >
        <el-row :gutter="24">
          <!-- <el-col :lg="5" :md="24">
            <el-form-item label="客户名称:">
              <el-select v-model="where.customerId" filterable clearable placeholder="请选择客户">
                <el-option v-for="(item, index) in customerDatas" :key="index" :label="item.name" :value="item.id" />
              </el-select>
            </el-form-item>
          </el-col> -->
          <el-col :lg="9" :md="24">
            <el-form-item label="收款日期:">
              <el-date-picker v-model="where.reviceDate" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="daterange"
                  range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 240px;">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :lg="5" :md="24" >
            <div class="ele-form-actions">
              <el-button
                type="primary"
                icon="el-icon-search"
                class="ele-btn-icon"
                @click="search"
              >
                查询
              </el-button>
              <el-button @click="reset">重置</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    </template>
   
    <script>
      const DEFAULT_WHERE = {
        preNum: '',    //关键字
        reviceDate:'',
        customerId:'',
      };

      import { QueryCustomerPageList } from '@/api/basicdatamanager/customer';
      export default {
        name: 'SaleOrderPrereviceitemSearch',
       
        data() {
          return {
            // 表单数据
            where: { ...DEFAULT_WHERE },
            customerDatas:[],
          };
        },
        //初始化数据
        created(){
          this.queryCustomerDatas();
        },
    
        methods: {
    
          /* 搜索 */
          search() {
            let params = {
              pageindex: 1,
              conditions: [],
              orderBys: [{ sort: "createDate", order: 1, }],
            };

            //单号
            if(this.where.preNum){
              params.conditions.push({
                key:"preNum",
                operator: 1,
                value:  this.where.preNum,
              });
            }

            if(this.where.customerId){
              params.conditions.push({
                key:"customerId",
                operator: 0,
                value: this.where.customerId,
              });
            }

            //收款日期
            if(this.where.reviceDate){
              params.conditions.push({
                  key:"reviceDate",
                  operator: 3,
                  value:  this.where.reviceDate[0] + " 00:00:00",
                });

              params.conditions.push({
                key:"reviceDate",
                operator: 5,
                value:  this.where.reviceDate[1] + " 23:59:59",
              });
            }

            this.$emit('search', params);
          },

          /*  重置 */
          reset() {
            this.where = { ...DEFAULT_WHERE };
            this.search();
          },

          /* 系统状态 */
          async queryCustomerDatas(){
            
            let params = {
              pageindex: 1,
              pagesize: 1000,
              conditions: [],
              orderBys: [{ sort: "createDate", order: 1, }],
            };

            params.conditions.push({
              key:"deleted",
              operator: 0,
              value: 0,
            });

            let result = await QueryCustomerPageList(params);
            this.customerDatas=[];
            this.customerDatas = result.items;
          },
        }
      };
    </script>
    